<?php
session_start();
if(isset($_GET['id']) && isset($_GET['temp']))
{
		
		if(!isset($_SESSION["listGame"]))
			$_SESSION["listGame"]=array();
		if(!isset($_SESSION["countGame"]))
			$_SESSION["countGame"]=0;
		if(!isset($_SESSION["totalSize"]))
			$_SESSION["totalSize"]=0;
		if(!isset($_SESSION["totalPrice"]))
			$_SESSION["totalPrice"]=0;
	
	$id = $_GET['id'];
	$temp = (int)$_GET['temp'];
	include_once("../DataProvider.php");
	$sql = "select * from tbl_games where gameID = " . $id;
	$result = DataProvider::ExecuteQuery($sql);
	$tongsorecord = mysql_num_rows($result);

	if($tongsorecord > 0){
		$row = mysql_fetch_array($result);
		if($temp==1)
		{
			$_SESSION["countGame"]++;
			if(!in_array($id,$_SESSION["listGame"]))
			{
				array_push($_SESSION["listGame"],$id);
			}
			
			
			$_SESSION["totalPrice"] += $row["Price"];
			$_SESSION["totalSize"] += $row["Size"];
			
		}
		else
		{
			if(($key = array_search($id,$_SESSION["listGame"]))>=0)
			{
				unset($_SESSION["listGame"][$key]);
			}
			$_SESSION["countGame"]--;
			$_SESSION["totalPrice"] -= $row["Price"];
			$_SESSION["totalSize"] -= $row["Size"];
			}
		}
		?>
     
	<script type="text/javascript">

	document.getElementById("countGame1").innerHTML = '<?php echo $_SESSION["countGame"] ?>'; 
	//document.getElementById("countGame2").innerHTML = '<?php echo $_SESSION["countGame"] ?>'; 
	
	document.getElementById("size1").innerHTML =' <?php if($_SESSION["totalSize"]>1000)	
	 		echo number_format($_SESSION["totalSize"]/1000,2,".",","). " GB"; 
		else
			echo number_format($_SESSION["totalSize"],2,".",",") . " MB";   ?>'; 
	//document.getElementById("size2").innerHTML = '<?php echo number_format($_SESSION["totalSize"],2,".",","); ?> ';
	
	document.getElementById("price1").innerHTML = '<?php echo number_format($_SESSION["totalPrice"],0,".",","); ?>'; 
	//document.getElementById("price2").innerHTML = '<?php echo number_format($_SESSION["totalPrice"],0,".",","); ?>'; 
      </script>  
		<?php 
		
}
	?>